package com.miku.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miku.blog.domain.SocialLogin;
import com.miku.blog.domain.pojo.SystemConstance;
import com.miku.blog.service.SocialLoginService;
import com.miku.blog.mapper.SocialLoginMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
* @author Miku
* @description 针对表【tb_social_login】的数据库操作Service实现
* @createDate 2022-06-08 08:47:10
*/
@Service
public class SocialLoginServiceImpl extends ServiceImpl<SocialLoginMapper, SocialLogin>
    implements SocialLoginService{



    @Override
    public List<SocialLogin> getSocialLogin(Integer webSiteId){
        LambdaQueryWrapper<SocialLogin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SocialLogin::getWebsiteId,webSiteId)
                .eq(SocialLogin::getIsDisable, SystemConstance.NOT_DISABLE);
        return list(queryWrapper);
    }


    @Override
    public boolean updateSocialLogin(SocialLogin socialLogin) {
        Integer isDisable = socialLogin.getIsDisable();
        if (Objects.isNull(isDisable)
                || (!SystemConstance.IS_DISABLE.equals(isDisable) && !SystemConstance.NOT_DISABLE.equals(isDisable))
        ){
            return false;
        }
        LambdaUpdateWrapper<SocialLogin> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SocialLogin::getWebsiteId,SystemConstance.WEBSITE_ID)
                .eq(SocialLogin::getLoginType,socialLogin.getLoginType())
                .set(SocialLogin::getIsDisable,socialLogin.getIsDisable());
        return update(updateWrapper);
    }
}




